<html>
<head><meta charset="utf-8"><title>consts referring to statics · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html">consts referring to statics</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="194557419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194557419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194557419">(Apr 18 2020 at 18:22)</a>:</h4>
<p>The past few days I've been playing with what we talked about in <a href="https://github.com/rust-lang/const-eval/issues/11" title="https://github.com/rust-lang/const-eval/issues/11">https://github.com/rust-lang/const-eval/issues/11</a>. I've got something that kinda works now, so I have some questions. :)</p>



<a name="194557434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194557434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194557434">(Apr 18 2020 at 18:23)</a>:</h4>
<p>First a simple one- should I put the changes to the dynamic check under the feature gate as well? Or is it okay to let it be more permissive unconditionally? AFAICT it just removes the errors from later in rustc, while leaving in the earlier ones.</p>



<a name="194557728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194557728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194557728">(Apr 18 2020 at 18:31)</a>:</h4>
<p>Second, it looks like there are two places that the dynamic check handles this? There's the <code>before_access_global</code> check that also handles mutability, which happens during interpretation, and then there's the final validation check afterwards. Is that correct, and is there anything special I need to do there? (Currently I'm just duplicating the ConservativeTransitiveFreeze check <span class="user-mention" data-user-id="124288">@oli</span> suggested for the static check.)</p>



<a name="194557790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194557790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194557790">(Apr 18 2020 at 18:32)</a>:</h4>
<p>And finally, I'm hitting the <code>span_mirbug!</code> from <a href="https://github.com/rust-lang/rust/pull/69145" title="https://github.com/rust-lang/rust/pull/69145">https://github.com/rust-lang/rust/pull/69145</a> in some cases (e.g. a const containing a raw pointer to a field of a static) where it seems like that check is a little too broad, and I suspect I'm missing something about how it's supposed to work.</p>



<a name="194571803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194571803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194571803">(Apr 19 2020 at 00:49)</a>:</h4>
<p>hmm I think I understand this last one now actually, after looking more closely at the tests in that PR and digging around the implementation</p>



<a name="194584343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194584343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194584343">(Apr 19 2020 at 07:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="117495">rpjohnst</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/consts.20referring.20to.20statics/near/194557434" title="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/consts.20referring.20to.20statics/near/194557434">said</a>:</p>
<blockquote>
<p>First a simple one- should I put the changes to the dynamic check under the feature gate as well? Or is it okay to let it be more permissive unconditionally? AFAICT it just removes the errors from later in rustc, while leaving in the earlier ones.</p>
</blockquote>
<p>I think we should change the dynamic check unconditionally. Maybe even in a separate PR, and definitely with a miri-unleash test.<br>
<span class="user-mention" data-user-id="124288">@oli</span> might disagree though.</p>



<a name="194584357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194584357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194584357">(Apr 19 2020 at 07:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="117495">rpjohnst</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/consts.20referring.20to.20statics/near/194557728" title="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/consts.20referring.20to.20statics/near/194557728">said</a>:</p>
<blockquote>
<p>Second, it looks like there are two places that the dynamic check handles this? There's the <code>before_access_global</code> check that also handles mutability, which happens during interpretation, and then there's the final validation check afterwards. Is that correct, and is there anything special I need to do there? (Currently I'm just duplicating the ConservativeTransitiveFreeze check <span class="user-mention silent" data-user-id="124288">oli</span> suggested for the static check.)</p>
</blockquote>
<p>I dont understand why the dynamic check would be conservative in any way? it should have 0 false positives.</p>



<a name="194584411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194584411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194584411">(Apr 19 2020 at 07:41)</a>:</h4>
<p>IMO the check in validity should just go away. <em>referencing</em> a static was never a problem, it was just rejected by the static check due to imprecision. You mean <a href="https://github.com/rust-lang/rust/blob/a0e52b1e82472e4890202082a0482b178f9d6a16/src/librustc_mir/interpret/validity.rs#L414" title="https://github.com/rust-lang/rust/blob/a0e52b1e82472e4890202082a0482b178f9d6a16/src/librustc_mir/interpret/validity.rs#L414">this one</a>, right?</p>



<a name="194584462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194584462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194584462">(Apr 19 2020 at 07:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="117495">rpjohnst</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/consts.20referring.20to.20statics/near/194557790" title="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/consts.20referring.20to.20statics/near/194557790">said</a>:</p>
<blockquote>
<p>And finally, I'm hitting the <code>span_mirbug!</code> from <a href="https://github.com/rust-lang/rust/pull/69145" title="https://github.com/rust-lang/rust/pull/69145">https://github.com/rust-lang/rust/pull/69145</a> in some cases (e.g. a const containing a raw pointer to a field of a static) where it seems like that check is a little too broad, and I suspect I'm missing something about how it's supposed to work.</p>
</blockquote>
<p>hm, I never even saw that <code>span_mirbug!</code> macro, now I wonder if we should use it for ICEing from Miri...</p>



<a name="194600802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194600802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194600802">(Apr 19 2020 at 14:39)</a>:</h4>
<blockquote>
<p>I dont understand why the dynamic check would be conservative in any way? it should have 0 false positives.</p>
</blockquote>
<p>I'm going based off of <a href="https://github.com/rust-lang/const-eval/issues/11#issuecomment-613545556" title="https://github.com/rust-lang/const-eval/issues/11#issuecomment-613545556">@**oli**'s comment</a> that mentioned query cycles. I guess that could have just been talking exclusively about the static check? If so I will think a bit more about what to check dynamically, exactly.</p>



<a name="194600893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194600893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194600893">(Apr 19 2020 at 14:41)</a>:</h4>
<p><span class="user-mention" data-user-id="117495">@rpjohnst</span> you just quoted me with no new text?^^</p>



<a name="194600944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194600944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194600944">(Apr 19 2020 at 14:42)</a>:</h4>
<p>Whoops, still trying to figure out zulip's UI a little. :)</p>



<a name="194600992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194600992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194600992">(Apr 19 2020 at 14:43)</a>:</h4>
<p><span class="user-mention" data-user-id="117495">@rpjohnst</span> Tip: if you click on the arrow down you see when hovering over a comment, there is a button "quote and reply".</p>



<a name="194600993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194600993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194600993">(Apr 19 2020 at 14:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/consts.20referring.20to.20statics/near/194584411" title="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/consts.20referring.20to.20statics/near/194584411">said</a>:</p>
<blockquote>
<p>IMO the check in validity should just go away. <em>referencing</em> a static was never a problem, it was just rejected by the static check due to imprecision. You mean <a href="https://github.com/rust-lang/rust/blob/a0e52b1e82472e4890202082a0482b178f9d6a16/src/librustc_mir/interpret/validity.rs#L414" title="https://github.com/rust-lang/rust/blob/a0e52b1e82472e4890202082a0482b178f9d6a16/src/librustc_mir/interpret/validity.rs#L414">this one</a>, right?</p>
</blockquote>
<p>Yeah, if that check is redundant I'll just remove it. :)</p>



<a name="194601047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194601047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194601047">(Apr 19 2020 at 14:44)</a>:</h4>
<p>You found it just before I commented :)</p>



<a name="194601302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194601302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194601302">(Apr 19 2020 at 14:48)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/consts.20referring.20to.20statics/near/194600992" title="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/consts.20referring.20to.20statics/near/194600992">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="117495">rpjohnst</span> Tip: if you click on the arrow down you see when hovering over a comment, there is a button "quote and reply".</p>
</blockquote>
<p>pro tip: the shortcut for that is to press the <code>&gt;</code> key when the comment is selected (with the blue border)</p>



<a name="194601334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194601334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194601334">(Apr 19 2020 at 14:49)</a>:</h4>
<blockquote>
<p>Yeah, if that check is redundant I'll just remove it. :)</p>
</blockquote>
<p>I think it is redundant and frankly confusing (as it's somehow blurring the line between our static and dynamic checking), but dont know <span class="user-mention" data-user-id="124288">@oli</span> 's position on that</p>



<a name="194601385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194601385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194601385">(Apr 19 2020 at 14:50)</a>:</h4>
<blockquote>
<p>I'm going based off of <span class="user-mention silent" data-user-id="124288">oli</span>'s comment that mentioned query cycles. I guess that could have just been talking exclusively about the static check? If so I will think a bit more about what to check dynamically, exactly.</p>
</blockquote>
<p>I think in that comment oli was just referring to he new static check</p>



<a name="194605658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194605658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194605658">(Apr 19 2020 at 16:21)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/consts.20referring.20to.20statics/near/194601334" title="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/consts.20referring.20to.20statics/near/194601334">said</a>:</p>
<blockquote>
<p>I think it is redundant and frankly confusing (as it's somehow blurring the line between our static and dynamic checking), but dont know <span class="user-mention silent" data-user-id="124288">oli</span> 's position on that</p>
</blockquote>
<p>Hmm, I think it is currently the thing responsible for the error messages in the miri-unleashed tests- it was masking the actual errors from <code>CompileTimeInterpreter::before_access_global</code></p>



<a name="194605744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194605744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194605744">(Apr 19 2020 at 16:22)</a>:</h4>
<p>But removing it, those errors just become ICEs because of <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_mir/interpret/validity.rs#L841" title="https://github.com/rust-lang/rust/blob/master/src/librustc_mir/interpret/validity.rs#L841">this check</a></p>



<a name="194606132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606132">(Apr 19 2020 at 16:28)</a>:</h4>
<p>ah, interesting... and annoying :/</p>



<a name="194606135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606135">(Apr 19 2020 at 16:28)</a>:</h4>
<p>the "reads" during validation shouldn't really count</p>



<a name="194606144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606144">(Apr 19 2020 at 16:28)</a>:</h4>
<p>or maybe we should just not recurse into statics when validating a const</p>



<a name="194606147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606147">(Apr 19 2020 at 16:28)</a>:</h4>
<p>and instead assume the static has already been validated</p>



<a name="194606157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606157">(Apr 19 2020 at 16:29)</a>:</h4>
<p>(potentially at a different type, but that is a hole we are already willing to tolerate for statics/consts defined in other crates)</p>



<a name="194606174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606174">(Apr 19 2020 at 16:29)</a>:</h4>
<p>Ahh, are you saying the dynamic check should only actually fire when the constant is used?</p>



<a name="194606264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606264">(Apr 19 2020 at 16:31)</a>:</h4>
<p>I'm not sure of the layering here, but I guess we could change the <code>ConstEvalErrorKind</code>'s <code>Into&lt;InterpError&gt;</code> impl to produce an <code>UndefinedBehavior</code> variant instead of a <code>MachineStop</code> variant in this case, to preserve the existing errors</p>



<a name="194606436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606436">(Apr 19 2020 at 16:35)</a>:</h4>
<p>the issue you are having here is that validation should only raise validation errors</p>



<a name="194606443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606443">(Apr 19 2020 at 16:35)</a>:</h4>
<p>so, "this thing has the wrong data there"</p>



<a name="194606453"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606453" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606453">(Apr 19 2020 at 16:35)</a>:</h4>
<p>"you read from a static" is just not an error that should ever come up from validation, it's not a validity property</p>



<a name="194606457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606457">(Apr 19 2020 at 16:35)</a>:</h4>
<p>we cannot tell from the final value of a const whether its computation read from a static</p>



<a name="194606462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606462">(Apr 19 2020 at 16:35)</a>:</h4>
<p>and the final value to a const that <em>points to</em> a static is entirely fine</p>



<a name="194606516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606516">(Apr 19 2020 at 16:36)</a>:</h4>
<p>but the thing is, validation is itself implemented inside the miri engine, so when validation reads values to check if they are valid, that read is checked to make sure we dont read from a static, and... boom</p>



<a name="194606542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606542">(Apr 19 2020 at 16:36)</a>:</h4>
<p>but that's just silly, this is not the program reading from a static, so the check shouldnt even fire</p>



<a name="194606549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606549">(Apr 19 2020 at 16:37)</a>:</h4>
<p>the easiest way to make that happen is to just stop the recursion at the boundary between the constant and the static</p>



<a name="194606589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606589">(Apr 19 2020 at 16:38)</a>:</h4>
<p>which would basically mean, <a href="https://github.com/rust-lang/rust/blob/36b1a9296cde2b773771710e9bbd608fd2eca35f/src/librustc_mir/interpret/validity.rs#L411" title="https://github.com/rust-lang/rust/blob/36b1a9296cde2b773771710e9bbd608fd2eca35f/src/librustc_mir/interpret/validity.rs#L411">here</a>, if <code>self.ecx.tcx.is_static(did)</code>, then do not recurse.</p>



<a name="194606639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194606639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194606639">(Apr 19 2020 at 16:38)</a>:</h4>
<p>Ahh right, that makes sense</p>



<a name="194616294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/consts%20referring%20to%20statics/near/194616294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/consts.20referring.20to.20statics.html#194616294">(Apr 19 2020 at 20:20)</a>:</h4>
<p>Alright, here's a PR for the dynamic check changes: <a href="https://github.com/rust-lang/rust/pull/71332" title="https://github.com/rust-lang/rust/pull/71332">https://github.com/rust-lang/rust/pull/71332</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>